package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.AnonymityDao;
import com.qfedu.entity.Anonymity;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Week;
import com.qfedu.service.AnonymityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnonymityServiceImpl implements AnonymityService {
    @Autowired
    private AnonymityDao anonymityDao;

    @Override
    public ResponseData<List<Anonymity>> findAllAnonymity(int pageIndex,int pageSize) {

        PageHelper.startPage(pageIndex,pageSize);
        List<Anonymity> anonymityList = anonymityDao.findAllAnonymity();

        PageInfo pageInfo = new PageInfo(anonymityList);

        int count = (int) pageInfo.getTotal();
        ResponseData<List<Anonymity>> responseData = new ResponseData<>();
        responseData.setCode(0);
        responseData.setData(anonymityList);
        responseData.setCount(count);
        responseData.setMsg("ok");
        return responseData;
    }

    @Override
    public boolean addAnonymity(Anonymity anonymity) {
        int result = anonymityDao.addAnonymity(anonymity);

        if(result > 0){
            return  true;
        }
        return false;
    }
}
